import cv2
import numpy as np

##########################################################################

cap = cv2.VideoCapture('../video/b.mp4')
number_of_frames = (int(cap.get(cv2.CAP_PROP_FRAME_COUNT))) ## total number of frames in the video
number_of_images = 5 ## number of images to analyse
frames_to_take = np.arange(1,(number_of_images+1))*((number_of_frames//number_of_images)-2)
print(frames_to_take)
all_images_required = [] 

##############################################################
try:
    count = 0 
    while(True):
        ret, frame = cap.read()
        frame = cv2.resize(frame,(640,480))
        # print(count)
        if count in frames_to_take:
            print( 'taken ---------', count)
            all_images_required.append(frame)

        cv2.imshow('frame',frame)
        count+=1
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
except:
    pass
###########################################
## now check the images
print(len(all_images_required))

import pickle
with open('frames.pkl', 'wb') as handle:
    pickle.dump(all_images_required, handle)
###############################